﻿package kliment.display.draw.shape {
	import flash.geom.Point;
	import kliment.display.draw.DrawStyle;
	
	/**
	 * ...
	 * @author Kliment
	 */
	public class BurstShape extends ShapeAbstract {
		
		public function BurstShape(center:Point, sides:int = 5, innerRadius:Number = 30, outerRadius:Number = 40, angle:Number = 0, drawStyle:DrawStyle = null) {
			super();
			if (sides>2) {
				var step:Number = (Math.PI * 2) / sides;
				var halfStep:Number = step / 2;
				var qtrStep:Number = step / 4;
				var start:Number = (angle/180)*Math.PI;
				var dx:Number, dy:Number, cx:Number, cy:Number;
				_setStyles(graphics, drawStyle);
				graphics.moveTo(center.x + (Math.cos(start) * outerRadius), center.y - (Math.sin(start) * outerRadius));
				for (var n:Number = 1; n <= sides; n++) {
					cx = center.x + Math.cos(start + (step * n) - (qtrStep * 3)) * (innerRadius / Math.cos(qtrStep));
					cy = center.y - Math.sin(start + (step * n) - (qtrStep * 3)) * (innerRadius / Math.cos(qtrStep));
					dx = center.x + Math.cos(start + (step * n) - halfStep) * innerRadius;
					dy = center.y - Math.sin(start + (step * n) - halfStep) * innerRadius;
					graphics.curveTo(cx, cy, dx, dy);
					cx = center.x + Math.cos(start + (step * n) - qtrStep) * (innerRadius / Math.cos(qtrStep));
					cy = center.y - Math.sin(start + (step * n) - qtrStep) * (innerRadius / Math.cos(qtrStep));
					dx = center.x + Math.cos(start + (step * n)) * outerRadius;
					dy = center.y - Math.sin(start + (step * n)) * outerRadius;
					graphics.curveTo(cx, cy, dx, dy);
				}
				graphics.endFill();
			}
		}
		
	}
	
}